'''
自动存取款机模拟
定义一个列表变量保存所有人的账户概信息
'''
list=[{"name":"Zhangsan","balance":2000,"password":12345},
		{"name":"Lisi","balance":2300,"password":12580},
		{"name":"Wangwu","balance":3000,"password":12306},
		{"name":"Zhaoliu","balance":4000,"password":66666}]

#定义一个检测用户密码是否正确的函数
def login():
	global x
	for i in range(len(list)):
		n=input("请输入您的账户名：")
		if n==list[i]["name"]:
			p=input("请输入您的密码：")
			if p==list[i]['password']:
				return i
				x=True
				print("密码正确，请继续：")
				break
			else:
				print("密码错误，请检查密码：")
			continue
		else:
			print("账户错误，请检查用户：")
			continue

#定义一个函数来输出用户的账户信息
def showList():
	print("="*40)
	print("{0:5}{1:5}{2:10}".format("name","balance","password"))
	print("-"*40)
	print("{0:5}{1:5}{2:10}".format(list[i]["name"],list[i]["balance"],list[i]["password"])

#登录界面：
while True:
	print("="*40)
	print("{0:5}{1:5}".format("1.查询账户","2.存款"))
	print("{0:5}{1:5}".format("3.取款","4.退出"))
	print("="*40)
	login()
	key=input("输入您的选择：")
    if key=="1":
    	print("1.查询账户信息")
    	showList()
    elif key=="2":
    	print("2.存款")
    	a=input("请输入存款金额：")
    	list[i]["balance"]+=a
    elif key=="3":
    	print("3.取款")
    	b=input("请输入取款金额：")
    	list[i]["balance"]-=b
    elif key=="4":
    	print("4.退出")
    	break
    else:
    	print("输入有误！请重新输入")

